package com.springboot.java0317springboot.iocdemo;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author lenovo
 * @Description
 * @Date2025-3-17 15:41
 */

@Component
public class Computer {
    //品牌
    @Value("华为")
    private String brand;
    //cpu
    @Qualifier("amd")
    @Autowired
    private Cpu cpu;

    //内存
    @Resource
    private Memory memory;

    @Autowired
    @Qualifier("aira") // 默认使用空调a
    private Air air;

    @Autowired
    @Qualifier("sonyTV") // 默认注入sony电视
    private TV tv;

    public void start(){
        System.out.println(brand + "电脑开机了");
        cpu.run();
        memory.read();
        memory.write();
        air.cool();
        tv.play();
    }

    @Override
    public String toString() {
        return "Computer{" +
                "brand='" + brand + '\'' +
                ", cpu=" + cpu +
                ", memory=" + memory +
                ", air=" + air +
                ", tv=" + tv +
                '}';
    }

    public TV getTv() {
        return tv;
    }

    public void setTv(TV tv) {
        this.tv = tv;
    }


    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
        this.brand = brand;
    }

    public Cpu getCpu() {
        return cpu;
    }

    public void setCpu(Cpu cpu) {
        this.cpu = cpu;
    }

    public Memory getMemory() {
        return memory;
    }

    public void setMemory(Memory memory) {
        this.memory = memory;
    }

    public Air getAir() {
        return air;
    }

    public void setAir(Air air) {
        this.air = air;
    }
}
